package com.example.app;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Christian on 14/02/14.
 */
public class TabPagerAdapter extends FragmentPagerAdapter {
    public TabPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        switch (i){
            case 0:
                return new MobaList();
            case 1:
                return new RtsList();
            case 2:
                return new FpsList();
            case 3:
                return new FightList();
        }
        return null;
    }

    @Override
    public int getCount() {
        return 4;
    }
}

class MobaList extends Fragment{
    private ArrayList<Noticia> items;
    ListView newsList;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_lista_noticias, container, false);
        items = new ArrayList<Noticia>();
        NewsListAdapter adapter = new NewsListAdapter(container.getContext(), R.layout.news_list_item, items);
        newsList = (ListView) rootView.findViewById(R.id.news_list);
        newsList.setAdapter(adapter);

        adapter.add(new Noticia("Lolzinho entrevista: Espeon", "Entrevista com profissional do LoL", getString(R.string.new_lol_1), R.drawable.lol));
        adapter.add(new Noticia("MLG - Futuro Campeonato no Brasil", "MLG abrirá franquia no Brasil", getString(R.string.new_dota_1), R.drawable.dota));


        newsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle extras = new Bundle();
                extras.putString("TITLE", items.get(i).getTitulo());
                extras.putString("CONTENT", items.get(i).getConteudo());
                extras.putString("FONT", "www.fontedanocitia.com");
                Intent intent = new Intent(view.getContext(), ConteudoNoticia.class);
                intent.putExtras(extras);
                adapterView.getContext().startActivity(intent);
                getActivity().overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
            }
        });
        return rootView;
    }
}
class RtsList extends Fragment{
    private ArrayList<Noticia> items;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_lista_noticias, container, false);
        items = new ArrayList<Noticia>();
        NewsListAdapter adapter = new NewsListAdapter(container.getContext(), R.layout.news_list_item, items);
        ListView newsList = (ListView) rootView.findViewById(R.id.news_list);
        newsList.setAdapter(adapter);

        adapter.add(new Noticia("Liquid’HerO vence a IEM Cologne", "Placar impressionate de Liquid'Her0", getString(R.string.new_starcraft_1), R.drawable.sc2));
        adapter.add(new Noticia("Gamepólitan GP-CUP – Neste Final de Semana", "Classificatórias nete fim de semana", getString(R.string.new_starcraft_2), R.drawable.sc2));


        newsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle extras = new Bundle();
                extras.putString("TITLE", items.get(i).getTitulo());
                extras.putString("CONTENT", items.get(i).getConteudo());
                extras.putString("FONT", "www.fontedanoticia.com");
                Intent intent = new Intent(view.getContext(), ConteudoNoticia.class);
                intent.putExtras(extras);
                adapterView.getContext().startActivity(intent);
                getActivity().overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
            }
        });

        return rootView;
    }
}

class FpsList extends Fragment{
    private ArrayList<Noticia> items;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_lista_noticias, container, false);
        items = new ArrayList<Noticia>();
        NewsListAdapter adapter = new NewsListAdapter(container.getContext(), R.layout.news_list_item, items);
        ListView newsList = (ListView) rootView.findViewById(R.id.news_list);
        newsList.setAdapter(adapter);

        adapter.add(new Noticia("CrossFire leva 2 times brasileiros para o mundial na China", "Campeonato brasileiro de CF.",
                getString(R.string.new_cf_1), R.drawable.cf));
        adapter.add(new Noticia("Documentário sobre os Golden Polish Five", "Time de CS ganhará filme?", getString(R.string.new_cs_1), R.drawable.counterstrike));


        newsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle extras = new Bundle();
                extras.putString("TITLE", items.get(i).getTitulo());
                extras.putString("CONTENT", items.get(i).getConteudo());
                extras.putString("FONT", "www.fontedanoticia.com");
                Intent intent = new Intent(view.getContext(), ConteudoNoticia.class);
                intent.putExtras(extras);
                adapterView.getContext().startActivity(intent);
                getActivity().overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
            }
        });

        return rootView;
    }
}

class FightList extends Fragment{
    private ArrayList<Noticia> items;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_lista_noticias, container, false);
        items = new ArrayList<Noticia>();
        NewsListAdapter adapter = new NewsListAdapter(container.getContext(), R.layout.news_list_item, items);
        ListView newsList = (ListView) rootView.findViewById(R.id.news_list);
        newsList.setAdapter(adapter);

        adapter.add(new Noticia("Breno F1ght3rs é campeão do REVOX 2014", "Breno bate ChuChu e é campeão invicto", getString(R.string.new_sf_1), R.drawable.sf4));
        adapter.add(new Noticia("Vergil e Dante que dão gosto de enfrentar", "Jogador do Amazonas faz bonito no REVOX", getString(R.string.new_mvc_1), R.drawable.mvc3));

        newsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Bundle extras = new Bundle();
                extras.putString("TITLE", items.get(i).getTitulo());
                extras.putString("CONTENT", items.get(i).getConteudo());
                extras.putString("FONT", "www.fontedanoticia.com");
                Intent intent = new Intent(view.getContext(), ConteudoNoticia.class);
                intent.putExtras(extras);
                adapterView.getContext().startActivity(intent);
                getActivity().overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
            }
        });

        return rootView;
    }
}

